package com.mall.db.api;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mall.db.mapper.CmsSubjectMapper;
import com.mall.domain.CmsSubject;
import com.mall.interface1.api.CmsSubjectApi;
import org.apache.commons.lang.StringUtils;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class CmsSubjectApiImpl implements CmsSubjectApi {

    @Autowired
    private CmsSubjectMapper cmsSubjectMapper;

    /**
     * 获取全部商品专题
     *
     * @return
     */
    @Override
    public List<CmsSubject> getAll() {
        return cmsSubjectMapper.getAll();
    }

    /**
     * 根据专题名称分页获取商品专题
     *
     * @param pageNum
     * @param pageSize
     * @param keyword
     * @return
     */
    @Override
    public Page<CmsSubject> getListByPage(Long pageNum, Long pageSize, String keyword) {
        Page<CmsSubject> page = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<CmsSubject> wrapper = new LambdaQueryWrapper<>();
        wrapper.like(StringUtils.isNotEmpty(keyword), CmsSubject::getCategoryName, keyword);
        return cmsSubjectMapper.selectPage(page, wrapper);
    }
}

